/*
 * @Author: Hp_lucky 1063512385@qq.com
 * @Date: 2024-09-24 14:40:08
 * @LastEditors: Hp_lucky 1063512385@qq.com
 * @LastEditTime: 2024-10-17 15:47:29
 * @FilePath: \lucky-rpg\assets\script\src\Basic\Model\Platform\PlatformBase.ts
 */
/* eslint-disable */
import { _decorator, Canvas, director, EventTouch, Node } from 'cc';
import { CallBackHandler } from '../PoolObj/CallBackHandler';
import { AdType } from '../../../Data/Types';
import { EventManager } from '../../Manager/EventManager';
import { BaseEventType, ShareType, SoundCode } from '../../Config/BaseEnum';
import { GravityModel } from '../../../SDK/GravityModel';
import { GameEventType, GEEvent, RecordType } from '../../../Game/Config/GameEnum';
import { DataMgr, GameData } from '../../Manager/DataManager';
import { GlobalParams, PlayerParams, ResParams } from '../../Config/DataConfig';
import { MainModel_Ins } from '../../../Game/Main/MainModel';
import { AudioManager } from '../../Manager/AudioManager';

export default abstract class PlatformBase {
  platformApi: any;
  systemInfo: any;
  $bannerAd: any;
  $bannerInit: boolean;
  $videoAd: any;
  $insertAd: any;
  protected $adIndex: AdType;
  protected $adParam: unknown[];
  $videoId: string;
  $bannerId: string;
  $insertId: string;

  $appCode: string;
  $loginCallback;

  protected $shareIndex: ShareType;
  protected $shareParam: unknown[];

  /** 平台初始化 */
  initFramework() {}
  /** 短震动 */
  openVibrateShort() {}
  /** 长震动 */
  openVibrateLong(t) {}
  /** 桌面图标 */
  sendDesktop(e) {}
  /** 调起添加桌面图标 */
  hasShortcutInstalled(e) {}
  /** 是否已添加桌面图标 */
  getIsDesktop() {}
  /** 播放音乐 */
  playMusic(e, t) {}
  /** 暂停音乐播放 */
  stopMusic() {}
  /** 播放音效 */
  playSound(e, t) {}
  /** 暂停音效 */
  stopSound(e) {}
  /** 退出游戏 */
  exitGame() {}
  /** 提示窗口 */
  showToast(e, i, d) {}
  createLupingBtn() {}
  createMoreGameBtn() {}
  addShortcut() {}
  checkShortcut() {}

  showBanner(e) {}
  openBanner(e) {}
  hideBanner() {}
  protected adFinish() {
    EventManager.Ins().emit(BaseEventType.GAME_AD_FINISH + this.$adIndex, ...this.$adParam);
    EventManager.Ins().emit(BaseEventType.GAME_AD_FINISH, this.$adIndex);
    GameData.changePlayerAttr(PlayerParams.adCount, 1);
    // 添加广告币奖励
    // GameData.changeResAttr(ResParams.resAdCoin, 2);
    // 触发资源变化事件，刷新UI
    // EventManager.Ins().emit(GameEventType.RESOURCE_CHANGE);

    // MainModel_Ins.adCount++;

    GravityModel.Ins().userSet({ accuAds: GameData.playerParams.get(PlayerParams.adCount) });
    console.log('上报广告展示结束');
    const data = DataMgr.tables.TbAdType.get(this.$adIndex);
    if (data) {
      GravityModel.Ins().track(GEEvent.AD_SHOW_END, { adPosition: data.str });
    } else {
      GravityModel.Ins().track(GEEvent.AD_SHOW_END, { adPosition: '广告id: ' + this.$adIndex });
    }
  }
  showVideo(index: AdType, ...args: unknown[]) {
    this.$adIndex = index;
    this.$adParam = args;
    // MainModel_Ins.adTimeLock = true;
    this.startShowVideo();
  }
  protected startShowVideo() {
    this.adFinish();
  }
  protected showVideoSuccess() {
    console.log('上报广告展示成功');
    const data = DataMgr.tables.TbAdType.get(this.$adIndex);
    if (data) {
      GravityModel.Ins().track(GEEvent.AD_SHOW, { adPosition: data.str });
    } else {
      GravityModel.Ins().track(GEEvent.AD_SHOW, { adPosition: '广告id: ' + this.$adIndex });
    }
    // const canvas = director.getScene().getComponentInChildren(Canvas);
    // canvas.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
  }
  // protected adClose: boolean = false;
  // onTouchStart() {
  //   if (this.adClose) {
  //     this.adClose = false;
  //     // const canvas = director.getScene().getComponentInChildren(Canvas);
  //     // canvas.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
  //   }
  // }

  loadUserInfo() {
    GameData.changePlayerAttr(PlayerParams.getUserInfo, true);
  }
  reportScene() {}
  customReport(sceneid: number, contentIDs: string[], _timesTamp: number) {}
  checkFeedSubscribeStatus(sceneId: number): Promise<void> {
    return null;
  }
  getLaunchOptionsSync() {
    return null;
  }
  requestFeedSubscribe(id: number, countent: string) {}
  requestSubscribeMessage() {}
  showInsertAd() {}
  loadNativeAd(e) {}
  showNativeInBox(e, t, i) {}
  showNativeInsert(e, t) {}
  showNativeInsertAd(e, i, a) {}
  showNativeBannerAd(e, i, a) {}
  showSmallNative(e) {}
  recordScreen() {}
  removeScreen() {}
  pauseRecord() {}
  showTTBanner(e) {}
  reportRankingList(e) {}
  getRankingList() {}
  showQQBox() {}
  navigateToVideo(e) {}
  jumpToDY() {}
  loadSubpackage(e, t) {}
  showElectPortalAd(e) {}
  showwxCustomAd(e, t) {}
  openContent(e, t) {}
  closeContent() {}
  showNativeIcon(e, t) {}
  showNativeBanner(e, t) {}
  showPlayBanner(e) {}
  getHttpId() {}
  onHasShortcutInstalled(e) {}
  /** 埋点上报 */
  trackEvent(e, o = null) {}
  AutoRecord(type: RecordType) {}
  checkScene() {}
  navigateToScene() {}

  shareEnergy(index: ShareType, ...args: unknown[]) {
    this.$shareIndex = index;
    this.$shareParam = args;
    this.startShare();
  }

  startShare() {
    this.shareComplate();
  }

  shareComplate() {
    EventManager.Ins().emit(BaseEventType.GAME_SHARE_FINISH + this.$shareIndex, ...this.$shareParam);
    EventManager.Ins().emit(BaseEventType.GAME_SHARE_FINISH, this.$shareIndex);
  }

  /** http请求 */
  abstract requestHttpGet(url: string, data: any, callback: CallBackHandler, headers?: { [key: string]: string });

  /** http请求 */
  abstract requestHttpPost(url: string, data: any, callback: CallBackHandler, headers?: { [key: string]: string });
  abstract login(callback?: CallBackHandler);

  abstract notifyMiniProgramPlayableStatus();
}
